import Vue from "vue";
import Router from "vue-router";
import layout from '@/views/layout';

// hack router push callback
// const originalPush = Router.prototype.push;
// Router.prototype.push = function push(location, onResolve, onReject) {
//     if (onResolve || onReject)
//         return originalPush.call(this, location, onResolve, onReject);
//     return originalPush.call(this, location).catch((err) => err);
// };

/**
 * 基础路由
 * @type { *[] }
 */
export const constantRouterMap = [
    {
        path: "/",
        hidden: true,
        redirect: "/general"
    },
    {
        path: "/home",
        name: "Home",
        component: layout,
        meta: { title: "首页" },
        children: [
            {
                path: "index",
                hidden: true,
                meta: { title: "首页" },
                component: () =>
                    import(/* webpackChunkName: "user" */ "@/views/navigation/affix")
            },
        ]
    },
    {
        path: "/general",
        component: layout,
        redirect: "/general/button",
        meta: { title: "通用", icon: 'user' },
        children: [
            {
                path: "button",
                name: "Button",
                meta: { title: "按钮" },
                component: () =>
                    import(/* webpackChunkName: "general" */ "@/views/general/button")
            },
            {
                path: "icon",
                name: "Icon",
                meta: { title: "图标" },
                component: () =>
                    import(/* webpackChunkName: "general" */ "@/views/general/icon")
            }
        ]
    },
    {
        path: "/navigation",
        component: layout,
        redirect: "/navigation/affix",
        meta: { title: "导航", icon: 'mail' },
        children: [
            {
                path: "affix",
                name: "Affix",
                meta: { title: "固钉" },
                component: () =>
                    import(/* webpackChunkName: "navigation" */ "@/views/navigation/affix")
            },
            {
                path: "breadcrumb",
                name: "Breadcrumb",
                meta: { title: "面包屑" },
                component: () =>
                    import(/* webpackChunkName: "navigation" */ "@/views/navigation/breadcrumb")
            },
            {
                path: "dropdown",
                name: "Dropdown",
                meta: { title: "下拉菜单" },
                component: () =>
                    import(/* webpackChunkName: "navigation" */ "@/views/navigation/dropdown")
            },
            {
                path: "pageHeader",
                name: "PageHeader",
                meta: { title: "页头" },
                component: () =>
                    import(/* webpackChunkName: "navigation" */ "@/views/navigation/pageHeader")
            },
            {
                path: "pagination",
                name: "Pagination",
                meta: { title: "分页" },
                component: () =>
                    import(/* webpackChunkName: "navigation" */ "@/views/navigation/pagination")
            },
            {
                path: "steps",
                name: "Steps",
                meta: { title: "步骤条" },
                component: () =>
                    import(/* webpackChunkName: "navigation" */ "@/views/navigation/steps")
            }
        ]
    },
    {
        path: "/dataEntry",
        component: layout,
        redirect: "/dataEntry/form",
        meta: { title: "数据录入", icon: 'mail' },
        children: [
            {
                path: "form",
                name: "Form",
                meta: { title: "表单" },
                component: () =>
                    import(/* webpackChunkName: "dataEntry" */ "@/views/dataEntry/form")
            }]
    },
    {
        path: "/dataDisplay",
        component: layout,
        redirect: "/dataDisplay/list",
        meta: { title: "数据展示", icon: 'mail' },
        children: [
            {
                path: "list",
                name: "List",
                meta: { title: "列表" },
                component: () =>
                    import(/* webpackChunkName: "dataDisplay" */ "@/views/dataDisplay/list")
            },
            {
                path: "table",
                name: "Table",
                meta: { title: "表格" },
                component: () =>
                    import(/* webpackChunkName: "dataDisplay" */ "@/views/dataDisplay/table")
            },
            {
                path: "excel",
                name: "Excel",
                meta: { title: "表格" },
                component: () =>
                    import(/* webpackChunkName: "dataDisplay" */ "@/views/dataDisplay/excel")
            },
            {
                path: "pdf",
                name: "Pdf",
                meta: { title: "PDF" },
                component: () =>
                    import(/* webpackChunkName: "dataDisplay" */ "@/views/dataDisplay/pdf")
            },
            {
                path: "clamp",
                name: "Clamp",
                meta: { title: "文本展开收起" },
                component: () =>
                    import(/* webpackChunkName: "dataDisplay" */ "@/views/dataDisplay/clamp")
            }]
    },
    {
        path: "/example",
        component: layout,
        redirect: "/example/drag",
        meta: { title: "小例子", icon: 'mail' },
        children: [
            {
                path: "css",
                name: "Css",
                meta: { title: "css" },
                component: () =>
                    import(/* webpackChunkName: "example" */ "@/views/example/css")
            },
            {
                path: "drag",
                name: "Drag",
                meta: { title: "拖拽" },
                component: () =>
                    import(/* webpackChunkName: "example" */ "@/views/example/drag")
            },
            {
                path: "guide",
                name: "Guide",
                meta: { title: "新手引导" },
                component: () =>
                    import(/* webpackChunkName: "example" */ "@/views/example/newbieGuide")
            },
            {
                path: "scroll",
                name: "Scroll",
                meta: { title: "虚拟滚动" },
                component: () =>
                    import(/* webpackChunkName: "example" */ "@/views/example/scroll")
            }
        ]
    },
    {
        path: "/404",
        hidden: true,
        component: () =>
            import(/* webpackChunkName: "fail" */ "@/views/exception/404")
    },
    { path: '*', redirect: '/404', hidden: true }
];

Vue.use(Router);

const router = new Router({
    mode: "history",
    routes: constantRouterMap
});

router.beforeEach((to, from, next) => {
    console.log('xxx', to, from);
    next();
})

export default router;
